package self.hoy.demo.cloud.nacos;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.List;

/**
 * @author 三共小不
 * @date 2021/6/28
 */
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
        ConfigurableEnvironment environment = context.getEnvironment();
        String name = environment.getProperty("user.name");
        String age = environment.getProperty("user.age");
        System.out.println(name + " " + age);
        DiscoveryClient bean = context.getBean(DiscoveryClient.class);
        List<String> services = bean.getServices();
        System.out.println(services);
        List<ServiceInstance> instances = bean.getInstances(services.get(0));
        System.out.println(instances);
    }
}
